package com.dateConstruction._08_search;

public class BinarySearch {
    
    public static <T extends Comparable<? super T>> int binarySearch(T[] values, int begin, int end, T key) {
        if (0 <= begin && begin <= end && end < values.length) {
            while (begin <= end) {
                int mid = (begin + end) / 2;
                if (key.compareTo(values[mid]) == 0) {
                    return mid;
                } else if (key.compareTo(values[mid]) < 0) {
                    end = mid - 1;
                } else if (key.compareTo(values[mid]) > 0) {
                    begin = mid + 1;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
    }

}
